package com.bite.order.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.bite.order.model.OrderInfo;
import com.bite.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.UndeclaredThrowableException;

@RequestMapping("/order")
@RestController
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @SentinelResource("/sentinel/id")
    @RequestMapping("/{orderId}")
    public OrderInfo getOrderById(@PathVariable("orderId") Integer orderId){
//        try {
//            OrderInfo orderInfo = orderService.selectOrderById(orderId);
//            return orderInfo;
//        }catch (UndeclaredThrowableException e){
//            log.error("获取订单详情发⽣异常, e:", e);
//            return new OrderInfo();
//        }
        return orderService.selectOrderById(orderId);
    }

    @RequestMapping("/write")
    public String write(){
        orderService.queryOrderInfo();
        return "写操作";
    }
    @RequestMapping("/read")
    public String read(){
        orderService.queryOrderInfo();
        return "读操作";
    }
}
